package com.ai.demo.controller;

import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
@RequiredArgsConstructor
public class ChatClientController {

    private final ChatClient client;

    @RequestMapping(value = "/chatStream", produces = "text/event-stream;charset=UTF-8")
    public Flux<String> chatStream(String prompt) {
        return client
                .prompt()
                .system(s -> s.text("以{style}风格回答").param("style", "古风"))
                .user(prompt)
                .stream()
                .content();
    }
}